package com.jiawa.train.business.controller.admin;


import com.jiawa.train.business.req.DailyTrainQueryReq;
import com.jiawa.train.business.req.DailyTrainSaveReq;
import com.jiawa.train.business.resp.DailyTrainQueryResp;
import com.jiawa.train.business.service.IDailyTrainService;
import com.jiawa.train.common.resp.CommonResp;
import com.jiawa.train.common.resp.PageResp;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 * 每日车次 前端控制器
 * </p>
 *
 * @author hrz
 * @since 2025-09-07
 */
@RestController
@RequestMapping("/admin/daily-train")
@RequiredArgsConstructor
public class DailyTrainAdminController {
    private final IDailyTrainService dailyTrainService;

    @PostMapping("/save")
    public CommonResp<Object> save(@Validated @RequestBody DailyTrainSaveReq Req) {
        dailyTrainService.saveDailyTrain(Req);
        return new CommonResp<>();
    }

    @GetMapping("/query-list")
    public CommonResp<PageResp<DailyTrainQueryResp>> queryList(@Validated DailyTrainQueryReq req) {
        PageResp<DailyTrainQueryResp> pa = dailyTrainService.queryList(req);
        return new CommonResp<>(pa);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable Long id) {
        dailyTrainService.delete(id);
        return new CommonResp<>();
    }

    @GetMapping("/gen-daily/{date}")
    public CommonResp<Object> generate(
            @PathVariable
            @DateTimeFormat(pattern = "yyyy-MM-dd")
            Date date) {
        dailyTrainService.generate(date);
        return new CommonResp<>();
    }
}
